<?php
/** [后台登录控制器]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-09 16:59:21
 * @Last Modified by:   Administrator
 * @Last Modified time: 2015-01-17 16:17:07
 */
class LoginAction extends ExtendAction{

	public $userLogic;
	/**
	 * [_initialize 初始化]
	 * @return [type] [description]
	 */
	public function _initialize()
	{
		$this->userLogic = D('User','Logic');
	}



	/**
	 * [ajax_check_code 验证码比较]
	 * @return [type] [description]
	 */
	public function ajax_check_code()
	{
		if(!$this->userLogic->check_code())
			$this->ajaxReturn(array('getdata'=>'false'));
		else
			$this->ajaxReturn(array('getdata'=>'true'));
	}

	/**
	 * [ajax_check_login 验证登录]
	 * @return [type] [description]
	 */
	public function ajax_check_login()
	{
		if(!$user = $this->userLogic->validate_login())
			$this->ajaxReturn(array('status'=>0,'info'=>$this->userLogic->getError()));
		else
		{
			// 更新登录信息
			$this->userLogic->update_login($user);
			// 设置session
			$this->userLogic->set_session($user);
			$this->ajaxReturn(array('status'=>1));
		}
	}


	/**
	 * [out 退出]
	 * @return [type] [description]
	 */
	public function out()
	{
		session(null);
		$this->redirect('Login/index');
	}
}